package com.dyh.quickdemo.demos.lvmhDemo;

import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/*
@Author=Joey Wheeler
@Date=2021/5/26 17:24
*/
@Component
public class AppReadyEventListener implements ApplicationListener<ApplicationReadyEvent> {

    @Resource
    List<AppReadyProcessor> appReadyReadyProcessors;

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {

        try {
            for (AppReadyProcessor appReadyReadyProcessor : appReadyReadyProcessors) {
                appReadyReadyProcessor.process(event);
            }
        } catch (Exception e) {

        } finally {
        }
    }

    @Bean
    AppReadyProcessor defaultAppReadyProcessor(){
        return event -> {};//什么都不做防止 appReadyReadyProcessors找不到bean报错
    }
}
